package com.freecloud.whispered.email.controller;

import com.freecloud.framework.request.R;
import com.freecloud.whispered.message.entity.Message;
import com.freecloud.whispered.message.service.MessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @Author: maomao
 * @Date: 2019-08-29 18:18
 */
@Api
@RestController
@RequestMapping("/test/message/email")
public class TestEmailController {

    @Autowired
    private MessageService messageService;

    @ApiOperation(value = "测试发送消息",notes = "测试发送消息")
    @GetMapping("/send")
    public R send(){

        long start = System.currentTimeMillis();

        Message message = new Message();
        message.setTitle("" + start);
        message.setContent("test email " + start);
        message.setUserId("1");

        messageService.send(message);

        long end = System.currentTimeMillis();

        System.out.println(String.format("send time : %s",end - start));


        System.out.println(String.format("sync send time : %s",end - start));

        return R.ok().put("time", end - start);
    }

    @ApiOperation(value = "测试发送消息",notes = "测试发送消息")
    @GetMapping("/syncSend")
    public R syncSend(){

        long start = System.currentTimeMillis();

        Message message = new Message();
        message.setTitle("" + start);
        message.setContent("sync test email " + start);
        message.setUserId("1");

        messageService.asyncSend(message);

        long end = System.currentTimeMillis();
        System.out.println(String.format("sync send time : %s",end - start));

        return R.ok().put("time", end - start);
    }
}
